<template>
	<view class="">
		<view style="background-color: #fff;">
			<view style="width: 400rpx;">
				<u-tabs :list="list" bar-width="120" :is-scroll="false" :current="billStatus" @change="change"></u-tabs>
			</view>
		</view>
		<view v-if="billStatus==0">
			<view class="a" v-for="(item,index) in cardList" :key="index">
				<view>
					<view class="owner">{{item.chargeItemName}}</view>
					<view>房屋信息：{{item.apartmentName + item.roomInfo}}</view>
					<view>创建时间：{{item.createTime}}</view>
					<view>账单周期：{{item.billingCycleRange}}</view>
					<u-tag style="width: 120rpx;text-align: center;"
						:text="$dictTools.dictTypeData('AUDIT_STATUS',item.auditStatus)" size="mini"
						:type="$dictTools.fileTag('AUDIT_STATUS',item.auditStatus)"></u-tag>
				</view>
				<view class="amount">{{'￥'+ item.amount}}</view>
			</view>
		</view>
		<view v-else>
			<view class="a" v-for="(item,index) in cardList" :key="index">
				<view>
					<view class="owner">{{item.chargeItemName}}</view>
					<view>创建时间：{{item.createTime}}</view>
					<view>账单周期：{{item.billingCycleRange}}</view>
					<view>支付时间：{{item.payTime}}</view>
					<view>优惠金额：{{'￥'+ item.deductionAmount}}</view>
				</view>
				<view class="amount">{{'￥'+ item.amount}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		billrecordPage
	} from '@/api/fin/billrecordApi.js'
	
	export default {
		data() {
			return {
				dateTime: '2023-05',
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				show: false,
				list: [{
					name: '待缴账单'
				}, {
					name: '已缴账单'
				}],
				billStatus: 0,
				roomId:'',
				cardList:[],
				billTypeId:'',
				parameter:{
					current: 1,
					size: 10
				},
				allDataLoaded: false
			}
		},
		mounted() {
			const query = this.$route.query;
			this.roomId = query.roomId;
			this.billTypeId = query.billTypeId;
		    this.loadData()
		  },
		methods: {
			async loadData() {
			     try {
						const parmas = {...this.parameter};
						const response = await billrecordPage({...parmas,roomId:this.roomId,billTypeId:this.billTypeId,billStatus:this.billStatus === 0 ? '1' : '2'})
			            if (response.records.length > 0) { // 如果有数据
			                      this.cardList = this.cardList.concat(response.records);
			                      this.parameter.current++
			                    } else {
			                      this.allDataLoaded = true;  // 数据已经全部加载完
			                 }
			     } catch (error) {
			       console.error('error', error)
			     }
			},
			async change(index) {
			  this.billStatus = index;
			  this.parameter.current = 1; 
			  this.cardList = []; 
			  await this.loadData();
			},
			affirmPicker(e) {
				this.dateTime = e.year + '-' + e.month
			},
			onReachBottom() {
				if (!this.allDataLoaded) {  // 如果数据还没有全部加载完才继续加载
				    this.loadData()
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.bill {
		&.tow {
			.selct {
				margin: 20rpx 30rpx;
				font-weight: 700;
			}
		}

		.not {
			display: flex;
			justify-content: center;
			margin-top: 200rpx;
			color: $-color-muted;
		}
	}
	/deep/.a{
			display: flex;
			justify-content: space-between;
			border-radius: 8px;
		    padding: 25px 10px 0 12px;
		    box-shadow: none;
		    background: #e5e5e547;
		    margin: 10px 10px 0 10px;
			color: #353535b0;
			.owner{
				color: #000;
				font-weight: 700;
				font-size: 34rpx;
			}
			.amount{
				font-size: 42rpx;
				line-height: 280rpx;
				color: #f7971eb3;
			}
			view{
				margin-bottom: 10px;
			}
		}
</style>